<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../libs/vue.js"></script>
</head>
<body>
    <div id="app">
        <h3 v-for="item in arr">{{item}}</h3>
        <hr>
        <button @click="addArr">点击向数组添加一个元素</button>
        <hr>
        <h3 v-for="(item,key) in obj">{{key}}=={{item}}</h3>
        <hr>
        <button @click="addObj">点击向对象添加一个元素</button>
    </div>
    <script>
        let vm = new Vue({
            el:'#app',
            data:{
                arr:['宝马','奔驰','奥迪'],
                obj:{
                    name:'张三',
                    age:20,
                    sex:'男'
                }
            },
            methods: {
                addArr(){
                    // this.arr.push('大众')
                    // this.arr[3] = '大众'
                    this.$set(this.arr,3,'奔腾')
                    console.log(this.arr)
                },
                addObj(){
                    this.obj.top = 180
                    // this.$set
                    // this.$set(this.obj,'top',180)
                    // 别名 Vue.set()
                    // Vue.set(this.obj,'height',175)
                    console.log(this.obj)
                    // 强制页面刷新
                    this.$forceUpdate()
                }
            },
        })
    </script>
</body>
</html>